#include "effectthread.h"
#include "toolkit.h"
#include "effecttoolkit.h"
#include <QDir>

EffectThread::EffectThread(QObject *parent) :
    QThread(parent)
{

}

EffectThread::~EffectThread()
{

}

void EffectThread::run()
{
    mutex.lock();

    switch(ToolKit::m_effectTp)
    {

    case GRAY_TYPE:
    {
        EffectToolKit::Gray(ToolKit::m_cameraImage);
    }
        break;

    case SHARPEN_TYPE:
    {
        EffectToolKit::Sharpen(ToolKit::m_cameraImage);
    }
        break;

    case FAINTLY_TYPE:
    {
        EffectToolKit::Faintly(ToolKit::m_cameraImage);
    }
        break;

    case EXPOSURE_TYPE:
    {
        EffectToolKit::Exposal(ToolKit::m_cameraImage);
    }
        break;

    case H150_TYPE:
    {
        EffectToolKit::h150(ToolKit::m_cameraImage);
    }
        break;

    case OLD_TYPE:
    {
        EffectToolKit::OldPhoto(ToolKit::m_cameraImage);
    }
        break;

    case H90_TYPE:
    {
        EffectToolKit::h90(ToolKit::m_cameraImage);
    }
        break;
    case BUBBLE_TYPE:
    {
        EffectToolKit::Bubble(ToolKit::m_cameraImage);
    }
        break;
    case H30_TYPE:
    {
        EffectToolKit::h30(ToolKit::m_cameraImage);
    }
        break;

    default:
        break;
    }

    QString strpath = ToolKit::m_path;
    int i = 0;
    strpath += QString("image%1.png").arg(i);
    QDir dir;
    while(dir.exists(strpath))
    {
        strpath = ToolKit::m_path + QString("image%1.png").arg(++i);
    }
    ToolKit::m_cameraImage->save(strpath,"png");

    ToolKit::m_strSelImage = strpath;
    mutex.unlock();
    emit effectThreadOver();
}
